package com.pk.platform.business.charge.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.pk.platform.business.charge.dao.IChargeTempDao;
import com.pk.platform.business.charge.vo.ChargeTempVO;
import com.pk.platform.business.core.dao.impl.GenericDaoImpl;
import com.pk.platform.domain.charge.ChargeTemp;
import com.pk.platform.domain.charge.TempIndexRef;
import com.pk.platform.util.StringConverter;
import com.pk.platform.util.constant.Constant;
import com.pk.platform.util.page.ListPage;
import com.pk.platform.util.page.Pager;

public class ChargeTempDaoImpl extends GenericDaoImpl implements IChargeTempDao {

	public List<ChargeTemp> queryChargeTempByClass(String classId) {
		String hql = "from ChargeTemp ct where ct.cla.id = ?";
		return this.getHibernateTemplate().find(hql, new Object[]{classId});
	}
	
	public ListPage queryChargeTemp(ChargeTempVO ctvo, Pager pager)
	{
		StringBuffer sql = new StringBuffer();
		sql.append("select ct.*, c.className from charge_temp ct left join cla c on ct.classId = c.id where 1 = 1");
		List<Object> param = new ArrayList<Object>();
		if(StringConverter.isNotNull(ctvo.getCt().getTempName()))
		{
			sql.append(" and ct.tempName like ?");
			param.add("%" + ctvo.getCt().getTempName() + "%");
		}
		if(StringConverter.isNotNull(ctvo.getCt().getDescription()))
		{
			sql.append(" and ct.description like ?");
			param.add("%" + ctvo.getCt().getDescription() + "%");
		}
		if(StringConverter.isNotNull(ctvo.getClassId()))
		{
			sql.append(" and ct.classId = ?");
			param.add(ctvo.getClassId());
		}
		if(StringConverter.isNotNull(ctvo.getKindergartenId()))
		{
			sql.append(" and ct.kgId = ?");
			param.add(ctvo.getKindergartenId());
		}
		sql.append(this.getKgData("ct", Constant.SQL));
		return this.getListPage(sql.toString(), param.toArray(), pager);
	}
	
	public List<TempIndexRef> queryTirList(String tempId)
	{
		String hql = "from TempIndexRef tir where tir.chargeTemp.id = ? order by tir.sort";
		return this.getHibernateTemplate().find(hql, new Object[]{tempId});
	}


}
